package com.tyoj.tyojbackendquestionservice.inner;

import com.tyoj.model.entity.Question;
import com.tyoj.model.entity.QuestionThumb;
import com.tyoj.tyojbackendclient.service.QuestionFeignClient;
import com.tyoj.tyojbackendquestionservice.mapper.QuestionThumbMapper;
import com.tyoj.tyojbackendquestionservice.service.QuestionService;
import com.tyoj.tyojbackendquestionservice.service.QuestionThumbService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/inner")
public class QuestionInnerController implements QuestionFeignClient {

    @Resource
    private QuestionService questionService;

    @Resource
    private QuestionThumbService questionThumbService;

    @Resource
    private QuestionThumbMapper questionThumbMapper;

    @Override
    @GetMapping("/get/id")
    public Question getQuestionById(long questionId) {
        return questionService.getById(questionId);
    }

    @Override
    @GetMapping("/question_submit/id")
    public QuestionThumb getQuestionSubmitById(@RequestParam("questionSubmitId") long questionSubmitId) {
        return questionThumbMapper.selectById(questionSubmitId);
    }

    @Override
    @PostMapping("/question_submit/update")
    public Boolean updateQuestionSubmitById(@RequestBody QuestionThumb updateQuestionSubmit) {
        int updateResult = questionThumbMapper.updateById(updateQuestionSubmit);
        return updateResult > 0 ? true : false;
    }
}
